import EditPhotoStore from '../editPhoto/store.js';
const app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    navbarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '', //导航栏 中间的标题
      background: 'linear-gradient(to bottom, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0))',
      hasFilter: true,
      color: '#FFFFFF',
      btnStyle: 'white', //black, white
    },
    navBarHeight: app.globalData.height,
    imgUrls:[],
    current:0,
    stopTouchMove:"",
    editDescFlag:false,
    coverPath:'',
    descObj:{}
  },
  photoTouchChange:function(e){
    this.setData({
      current: e.detail.current,
      editDescFlag:false
    });
  },
  clickPhoto:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  stopTouchMove: function () {
    return false
  },
  scaleChange: function (e) {
    let curScale = e.detail.curScale;
    let stopTouchMove = this.data.stopTouchMove;
    let value;
    if (curScale == 1) {
      value = "";
    } else {
      value = "stopTouchMove"
    } 
    if (stopTouchMove != value) {
      this.setData({
        stopTouchMove: value
      })
    }

  },
  isEditDesc:function(){
    this.setData({
      editDescFlag: !this.data.editDescFlag
    })
  },
  setCover:function(e){
    let curPath = e.currentTarget.dataset.path;
    if (curPath === EditPhotoStore.coverPath){
      return;
    }
    this.setData({
      coverPath: curPath
    },()=>{
      EditPhotoStore.setCover(curPath);
    })
   
  },
  updateDesc:function(e){
    let value = e.detail.value;
    let curPath = e.currentTarget.dataset.path;
    let descObj = this.data.descObj;
    descObj[curPath] = value;
    this.setData({
      descObj: descObj
    },()=>{
      EditPhotoStore.updateDesc({
        key: curPath,
        value: value
      })
    })
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let resourceType = options.resourceType;
    let imgUrls = [];
    if (resourceType == 0) {
      imgUrls.push(options.photoList);
    }else{
      imgUrls = options.photoList.replace(/,$/gi, "").split(',');
    }
    let dataObj = {
      imgUrls: imgUrls,
      resourceType: resourceType
    }
    if (options.selectedNum !== undefined){
      dataObj.current = parseInt(options.selectedNum);
      if (options.fromPage !== 'comments'){
        dataObj.coverPath = EditPhotoStore.coverPath;
        dataObj.descObj = EditPhotoStore.descObj
      }
    }
    this.setData(dataObj)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  
  // }
})